﻿using System;
using System.Collections.Generic;
using Character;
using H;
using UnityEngine;
using Utility;

// Token: 0x0200023A RID: 570
public class H_Visitor
{
	// Token: 0x06000F56 RID: 3926 RVA: 0x00062024 File Offset: 0x00060224
	public H_Visitor(H_Scene h_scene, HEROINE heroineID, CustomParameter param, RuntimeAnimatorController runtimeAC, H_VisitorVoice visitorVoice, H_VisitorExpression visitorExpression)
	{
		this.h_scene = h_scene;
		this.female = ResourceUtility.CreateInstance<Female>("FemaleBody");
		this.female.SetHeroineID(heroineID);
		this.female.Load(param, true);
		this.female.Apply();
		this.female.body.Anime.runtimeAnimatorController = runtimeAC;
		this.female.personality.H_In();
		this.human = this.female;
		this.Foot(h_scene.map.data.foot);
		this.voice = visitorVoice;
		this.expression = visitorExpression;
		this.NextVoiceTime();
		this.LockPos = false;
	}

	// Token: 0x06000F57 RID: 3927 RVA: 0x00062118 File Offset: 0x00060318
	public H_Visitor(H_Scene h_scene, MALE_ID maleID, CustomParameter param, RuntimeAnimatorController runtimeAC)
	{
		this.h_scene = h_scene;
		Male male = ResourceUtility.CreateInstance<Male>("MaleBody");
		male.SetMaleID(maleID);
		male.Load(param, true);
		male.Apply();
		male.body.Anime.runtimeAnimatorController = runtimeAC;
		this.human = male;
		this.Foot(h_scene.map.data.foot);
		this.voice = null;
		this.expression = null;
		this.LockPos = false;
	}

	// Token: 0x17000187 RID: 391
	// (get) Token: 0x06000F58 RID: 3928 RVA: 0x000621D4 File Offset: 0x000603D4
	// (set) Token: 0x06000F59 RID: 3929 RVA: 0x000621DC File Offset: 0x000603DC
	public bool LockPos { get; set; }

	// Token: 0x06000F5A RID: 3930 RVA: 0x000621E8 File Offset: 0x000603E8
	public void LoadAC(SEX sex)
	{
		AssetBundleController assetBundleController = new AssetBundleController();
		assetBundleController.OpenFromFile(GlobalData.assetBundlePath, "h/h_visitor");
		RuntimeAnimatorController runtimeAnimatorController;
		if (sex == SEX.FEMALE)
		{
			runtimeAnimatorController = assetBundleController.LoadAsset<RuntimeAnimatorController>("AC_Visitor");
		}
		else
		{
			runtimeAnimatorController = assetBundleController.LoadAsset<RuntimeAnimatorController>("AC_Visitor_M");
		}
		this.human.body.Anime.runtimeAnimatorController = runtimeAnimatorController;
		this.human.body.Anime.speed = 1f;
		assetBundleController.Close(false);
	}

	// Token: 0x06000F5B RID: 3931 RVA: 0x00062268 File Offset: 0x00060468
	public void SwapHuman(Human newHuman, AssetBundleController abc, H_Members members, bool setOnly)
	{
		this.human = newHuman;
		this.female = (this.human as Female);
		if (!setOnly)
		{
			this.human.GagShow = true;
			this.LoadAC(this.human.sex);
			this.voice.Voice(this.female, this.log, abc, H_VisitorVoice.TYPE.BREATH, members);
			this.Expression(H_VisitorExpression.TYPE.BREATH);
		}
	}

	// Token: 0x06000F5C RID: 3932 RVA: 0x000622D4 File Offset: 0x000604D4
	public void Update()
	{
		int count = this.h_scene.mainMembers.GetFemales().Count;
		bool flag = true;
		if (!flag || count > 1)
		{
			return;
		}
		if (this.updateLookDelay >= 0)
		{
			if (this.updateLookDelay == 0)
			{
				Transform tgt = this.h_scene.mainMembers.CaclVisitorLookPos();
				this.human.ChangeNeckLook(LookAtRotator.TYPE.TARGET, tgt, false);
				this.human.ChangeEyeLook(LookAtRotator.TYPE.TARGET, tgt, false);
				this.updateLookDelay = -1;
			}
			this.updateLookDelay--;
		}
		this.human.body.Anime.SetFloat("Height", this.human.customParam.body.GetHeight());
		if (this.female != null)
		{
			this.voiceTimer -= Time.deltaTime;
			if (this.voiceTimer <= 0f)
			{
				this.h_scene.VisitorVoiceExpression(H_VisitorVoice.TYPE.GENERAL);
			}
			this.log.Update();
			if (!this.female.IsVoicePlaying())
			{
				this.h_scene.VisitorVoiceExpression(H_VisitorVoice.TYPE.BREATH);
			}
			if (this.expressionTimer <= 0f)
			{
				this.Expression(H_VisitorExpression.TYPE.BREATH);
			}
			else
			{
				this.expressionTimer -= Time.deltaTime;
			}
		}
	}

	// Token: 0x06000F5D RID: 3933 RVA: 0x00062428 File Offset: 0x00060628
	public bool VoiceExpression(H_VisitorVoice.TYPE type, AssetBundleController abc, H_Members members)
	{
		if (this.voice == null)
		{
			return false;
		}
		H_VisitorVoice.Data data = this.voice.Voice(this.female, this.log, abc, type, members);
		if (data != null)
		{
			this.expression.ChangeExpression(this.female, data.file);
			this.NextVoiceTime();
			this.NextExpressionTime();
			return true;
		}
		return false;
	}

	// Token: 0x06000F5E RID: 3934 RVA: 0x00062490 File Offset: 0x00060690
	public void Expression(H_VisitorExpression.TYPE type)
	{
		this.expression.ChangeExpression(this.female, type);
		this.NextExpressionTime();
	}

	// Token: 0x06000F5F RID: 3935 RVA: 0x000624AC File Offset: 0x000606AC
	public void RandomPose(Dictionary<string, H_PoseData> poseDatas, H_Pos h_pos)
	{
		this.poseDatas = poseDatas;
		this.h_pos = h_pos;
		if (h_pos.watchPos.Count == 0)
		{
			return;
		}
		this.posNo = UnityEngine.Random.Range(0, h_pos.watchPos.Count);
		this.ChangePose();
	}

	// Token: 0x06000F60 RID: 3936 RVA: 0x000624EC File Offset: 0x000606EC
	public void SetPose(Dictionary<string, H_PoseData> poseDatas, H_Pos h_pos, int no)
	{
		this.poseDatas = poseDatas;
		this.h_pos = h_pos;
		if (h_pos.watchPos.Count == 0)
		{
			return;
		}
		this.posNo = no % h_pos.watchPos.Count;
		this.ChangePose();
	}

	// Token: 0x06000F61 RID: 3937 RVA: 0x00062528 File Offset: 0x00060728
	public void ChangePose()
	{
		if (this.female != null)
		{
			this.ChangePose_F();
		}
		else
		{
			this.ChangePose_M();
		}
	}

	// Token: 0x06000F62 RID: 3938 RVA: 0x0006254C File Offset: 0x0006074C
	private void ChangePose_F()
	{
		if (!this.LockPos)
		{
			WatchPos watchPos = this.h_pos.watchPos[this.posNo];
			string[] array = new string[]
			{
				"Ritsuko",
				"Akiko",
				"Yukiko",
				"Mariko"
			};
			string str = array[(int)this.female.HeroineID];
			string[] array2 = new string[]
			{
				"Stand",
				"Floor",
				"Chair"
			};
			string str2 = (!GlobalData.PlayData.IsHeroineFloped(this.female.HeroineID)) ? "Resist" : "Flop";
			string key = str + str2 + array2[(int)watchPos.type];
			this.SetPos(watchPos);
			H_PoseData data = this.poseDatas[key];
			this.Pose(data);
		}
		this.updateLookDelay = 1;
	}

	// Token: 0x06000F63 RID: 3939 RVA: 0x00062634 File Offset: 0x00060834
	private void ChangePose_M()
	{
		if (!this.LockPos)
		{
			WatchPos pos = this.h_pos.watchPos[this.posNo];
			this.SetPos(pos);
		}
		this.updateLookDelay = 1;
	}

	// Token: 0x06000F64 RID: 3940 RVA: 0x00062674 File Offset: 0x00060874
	private void SetPos(WatchPos watchPos)
	{
		this.lastPosYaw = watchPos.pos;
		this.human.transform.position = watchPos.pos.pos;
		this.human.transform.rotation = Quaternion.Euler(0f, watchPos.pos.yaw, 0f);
	}

	// Token: 0x06000F65 RID: 3941 RVA: 0x000626D4 File Offset: 0x000608D4
	public void NextPos()
	{
		if (this.h_pos.watchPos.Count == 0)
		{
			return;
		}
		this.posNo = (this.posNo + 1) % this.h_pos.watchPos.Count;
		WatchPos watchPos = this.h_pos.watchPos[this.posNo];
		this.ChangePose();
	}

	// Token: 0x06000F66 RID: 3942 RVA: 0x00062734 File Offset: 0x00060934
	public void PrevPos()
	{
		if (this.h_pos.watchPos.Count == 0)
		{
			return;
		}
		this.posNo = (this.h_pos.watchPos.Count + this.posNo - 1) % this.h_pos.watchPos.Count;
		WatchPos watchPos = this.h_pos.watchPos[this.posNo];
		this.ChangePose();
	}

	// Token: 0x06000F67 RID: 3943 RVA: 0x000627A4 File Offset: 0x000609A4
	private void Pose(H_PoseData data)
	{
		this.PlayAnime(data.id, 0f);
		this.SetIK(this.human, data.ikDatas);
	}

	// Token: 0x06000F68 RID: 3944 RVA: 0x000627CC File Offset: 0x000609CC
	private void SetIK(Human human, IK_DataList dataList)
	{
		human.ik.ClearIK();
		if (dataList != null)
		{
			foreach (IK_Data data in dataList.ikDatas)
			{
				this.SetIK(data, 2f);
			}
		}
	}

	// Token: 0x06000F69 RID: 3945 RVA: 0x00062840 File Offset: 0x00060A40
	private void SetIK(IK_Data data, float speed)
	{
		bool flag = false;
		Human humanFromString = this.GetHumanFromString(data.ikChara);
		Transform iktargetFromString = this.GetIKTargetFromString(data.targetChara);
		if (humanFromString == null)
		{
			flag = true;
		}
		if (iktargetFromString == null)
		{
			flag = true;
		}
		if (flag)
		{
			return;
		}
		Transform transform = Transform_Utility.FindTransform(iktargetFromString, data.targetPart);
		if (transform != null)
		{
			humanFromString.ik.SetIK(data.ikPart, transform, speed);
		}
		else
		{
			GlobalData.Debug_LogError("不明的目标:" + data.targetPart);
		}
	}

	// Token: 0x06000F6A RID: 3946 RVA: 0x000628D4 File Offset: 0x00060AD4
	private Human GetHumanFromString(string str)
	{
		if (this.human.sex == SEX.FEMALE && str == "f0")
		{
			return this.human;
		}
		if (this.human.sex == SEX.MALE && str == "m0")
		{
			return this.human;
		}
		return null;
	}

	// Token: 0x06000F6B RID: 3947 RVA: 0x00062934 File Offset: 0x00060B34
	private Transform GetIKTargetFromString(string str)
	{
		if (this.human.sex == SEX.FEMALE && str == "f0")
		{
			return this.human.body.Anime.transform;
		}
		if (this.human.sex == SEX.MALE && str == "m0")
		{
			return this.human.body.Anime.transform;
		}
		return null;
	}

	// Token: 0x06000F6C RID: 3948 RVA: 0x000629B0 File Offset: 0x00060BB0
	public void PlayAnime(string name, float transitionDuration)
	{
		Animator anime = this.human.body.Anime;
		if (transitionDuration <= 0f)
		{
			anime.Play(name, 0);
		}
		else
		{
			anime.CrossFadeInFixedTime(name, transitionDuration, 0);
		}
	}

	// Token: 0x06000F6D RID: 3949 RVA: 0x000629F0 File Offset: 0x00060BF0
	public void Foot(MapData.FOOT foot)
	{
		this.human.Foot(foot);
	}

	// Token: 0x06000F6E RID: 3950 RVA: 0x00062A00 File Offset: 0x00060C00
	public Human GetHuman()
	{
		return this.human;
	}

	// Token: 0x06000F6F RID: 3951 RVA: 0x00062A08 File Offset: 0x00060C08
	public Female GetFemale()
	{
		return this.female;
	}

	// Token: 0x06000F70 RID: 3952 RVA: 0x00062A10 File Offset: 0x00060C10
	public bool IsFemale()
	{
		return this.female != null;
	}

	// Token: 0x06000F71 RID: 3953 RVA: 0x00062A20 File Offset: 0x00060C20
	public H_Pos GetH_Pos()
	{
		return this.h_pos;
	}

	// Token: 0x06000F72 RID: 3954 RVA: 0x00062A28 File Offset: 0x00060C28
	public PosYaw GetLastPosYaw()
	{
		return this.lastPosYaw;
	}

	// Token: 0x06000F73 RID: 3955 RVA: 0x00062A30 File Offset: 0x00060C30
	private void NextVoiceTime()
	{
		this.voiceTimer = UnityEngine.Random.Range(this.voiceTimeMin, this.voiceTimeMax);
	}

	// Token: 0x06000F74 RID: 3956 RVA: 0x00062A4C File Offset: 0x00060C4C
	private void NextExpressionTime()
	{
		this.expressionTimer = UnityEngine.Random.Range(this.expressionTimeMin, this.expressionTimeMax);
	}

	// Token: 0x04001040 RID: 4160
	private H_Scene h_scene;

	// Token: 0x04001041 RID: 4161
	private Human human;

	// Token: 0x04001042 RID: 4162
	private Female female;

	// Token: 0x04001043 RID: 4163
	private Dictionary<string, H_PoseData> poseDatas;

	// Token: 0x04001044 RID: 4164
	private H_Pos h_pos;

	// Token: 0x04001045 RID: 4165
	private int posNo;

	// Token: 0x04001046 RID: 4166
	private PosYaw lastPosYaw;

	// Token: 0x04001047 RID: 4167
	private int updateLookDelay = -1;

	// Token: 0x04001048 RID: 4168
	private float voiceTimer;

	// Token: 0x04001049 RID: 4169
	private float voiceTimeMin = 10f;

	// Token: 0x0400104A RID: 4170
	private float voiceTimeMax = 60f;

	// Token: 0x0400104B RID: 4171
	private float expressionTimer;

	// Token: 0x0400104C RID: 4172
	private float expressionTimeMin = 5f;

	// Token: 0x0400104D RID: 4173
	private float expressionTimeMax = 10f;

	// Token: 0x0400104E RID: 4174
	private H_VisitorVoice voice;

	// Token: 0x0400104F RID: 4175
	private H_VoiceLog log = new H_VoiceLog();

	// Token: 0x04001050 RID: 4176
	private H_VisitorExpression expression;
}
